package com.example.libowu.musicplayer;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * Created by libowu on 17-12-10.
 */

public class searcharMusiAdapter extends RecyclerView.Adapter<searcharMusiAdapter.Adapter> {
    private List<searcharMusic> searcharMusics;
    private searchOnclick se;


    public class Adapter extends RecyclerView.ViewHolder {
        private TextView contentSearch;
        private LinearLayout search;
        public Adapter(View itemView) {
            super(itemView);
            contentSearch=(TextView) itemView.findViewById(R.id.content_search);
            search=(LinearLayout) itemView.findViewById(R.id.search);
        }
    }

    public searcharMusiAdapter(List<searcharMusic> list,searchOnclick searchOnclick){
        searcharMusics=list;
        se=searchOnclick;
    }
    @Override
    public Adapter onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.searchar,parent,false);
        Adapter a=new Adapter(view);
        return a;
    }

    @Override
    public void onBindViewHolder(Adapter holder, int position) {
        final searcharMusic sm=searcharMusics.get(position);
        holder.contentSearch.setText(sm.getSongN());

        holder.search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                se.searchOnclick(sm.getSongId(),sm.getSongPath(),sm.getSongImgPath(),sm.getSongN());
            }
        });
    }

    @Override
    public int getItemCount() {
        return searcharMusics.size();
    }

}
